package com.productclass;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.dao.CategroryDao;

public class DeleteProductClass_servlet extends HttpServlet {

	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html,utf-8");
		CategroryDao dao = new CategroryDao();
		int delId = 1000;//id
		int idd = 0;//父节点
		//得到前台页面id值并判断其不为空
		if(request.getParameter("id") != null){
			
			try{
			delId = Integer.parseInt(request.getParameter("id"));
			System.out.println(delId);
			}catch (Exception e) {
				// TODO: handle exception
			}
			
		}else{
			response.sendRedirect("prompt/error.jsp");
		}
		//得到前台页面父节点的值 并判断
		if(request.getParameter("idd") != null){
			idd = Integer.parseInt(request.getParameter("idd"));
			System.out.println(idd);
		}
		//调用删除方法 
		try {
			int a = dao.delete(delId,idd);
			if(a > 0){
				
				response.sendRedirect("productClassServlet_s");
			}else{
				System.out.println("error");
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
	}
		
	

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doGet(request, response);
	}

}
